package sns.action;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Tag;
import sns.dao.TagDao;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class DeleteTagAction extends ActionSupport {

	// injection
	TagDao tagDao;
	// pass in
	private Long tagId;
	private Long visitId;

	// return
	// visitId
	@Transactional
	public String execute() {

		if (tagId == null) {
			System.out.println("Tag Id is null");
			return ActionSupport.INPUT;
		}

		if (visitId == null) {
			System.out.println("No visit id.");
			return ActionSupport.INPUT;
		}

		Tag tag = tagDao.getTagById(tagId);
		if (tag != null) {
			tagDao.delete(tag);
		} else {
			System.out.println("There is no such Tag.");
			return ActionSupport.ERROR;
		}

		return ActionSupport.SUCCESS;
	}

	public Long getVisitId() {
		return visitId;
	}

	public void setVisitId(Long visitId) {
		this.visitId = visitId;
	}

	public void setTagDao(TagDao tagDao) {
		this.tagDao = tagDao;
	}

	public void setTagId(Long tagId) {
		this.tagId = tagId;
	}

}
